//
//  VCTabBarController.m
//  VCShop
//
//  Created by VoyageCN on 16/8/17.
//  Copyright © 2016年 VoyageCN. All rights reserved.
//

#import "VCTabBarController.h"
#import "VCNavigationViewController.h"

@interface VCTabBarController ()

@property (nonatomic, strong) NSArray *tabBarContentArray;

@end

@implementation VCTabBarController

- (NSArray *)tabBarContentArray {
    
    if (!_tabBarContentArray) {
        _tabBarContentArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"VCTabBarController" ofType:@"plist"]];
    }
    return _tabBarContentArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.0f],
                                                      NSForegroundColorAttributeName:[UIColor grayColor]} forState:(UIControlStateNormal)];
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.0f],
                                                       NSForegroundColorAttributeName:[UIColor colorWithRed:57.0/255.0 green:167.0/255.0 blue:241.0/255.0 alpha:1]} forState:(UIControlStateSelected)];
    
    
    
    for (NSDictionary *dict in self.tabBarContentArray) {
        
        Class viewControllerClass = NSClassFromString(dict[@"tabbarController"]);
        UIViewController *viewController = [[viewControllerClass alloc] init];
        viewController.tabBarItem.image = [[UIImage imageNamed:dict[@"tabbarImage"]] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
        viewController.tabBarItem.selectedImage = [[UIImage imageNamed:dict[@"tabbarSelectImage"]] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
        
        viewController.title = dict[@"title"];
        VCNavigationViewController *nav = [[VCNavigationViewController alloc] initWithRootViewController:viewController];
        [self addChildViewController:nav];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
